#!/bin/sh
set -eu
root='/opt/GSB Software'
if [ "$(id -u)" = 0 ]; then printf '%s
' 'Abra o GSB com seu usuário da sessão gráfica.' >&2; exit 1; fi
# Integration runs as the desktop user, never as the privileged package installer.
desktop=$(xdg-user-dir DESKTOP 2>/dev/null || printf '%s/Desktop' "$HOME")
case "$desktop" in /*) ;; *) desktop="$HOME/Desktop" ;; esac
if [ "$desktop" != "$HOME" ]; then
  mkdir -p "$desktop"
  shortcut="$desktop/GSB Software.desktop"
  if [ ! -L "$shortcut" ] && { [ ! -e "$shortcut" ] || grep -q '^X-GSB-Managed=true$' "$shortcut"; }; then
    cp "$root/GSB Software.desktop" "$shortcut"
    chmod 755 "$shortcut"
    if command -v gio >/dev/null 2>&1; then gio set "$shortcut" metadata::trusted true >/dev/null 2>&1 || true; fi
  fi
fi
if [ "${1:-}" = --integrate ]; then exit 0; fi
exec "$root/app/GSB Software" "$@"
